home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Grafik / CreateIndex / BatchProcess.isrx next >
Text File  |  1998-06-21  |  10KB  |  408 lines

  1. /* ImageStudio ARexx script **************************************/
  2.  
  3. /* Allow commands to return results */
  4.  
  5. options results
  6.  
  7. /* On error, goto ERROR:. Comment out this line if you wish to */
  8. /* perform your own error checking. */
  9.  
  10. signal on error
  11.  
  12. /* BEGIN PROGRAM *************************************************/
  13.  
  14. /* Warn the user if they are about to overwrite their current project */
  15.  
  16. IMAGEINFO_GET STEM imageinfo.
  17.  
  18. if imageinfo.changed == 1 then
  19.     REQUEST_MESSAGE TEXT '"Project has changed, continue?"',
  20.         BUTTONTEXT '"OK|Cancel"' AUTOCANCEL
  21.  
  22. /* Choose source files */
  23.  
  24. REQUEST_MULTIFILE TITLE '"Choose source files..."' STEM srcfiles.
  25.  
  26. /* Use separate destination directory ? */
  27.  
  28. REQUEST_MESSAGE TEXT '"Use different destination directory?"',
  29.     BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  30.  
  31. if result == 1 then
  32.     REQUEST_DIR TITLE '"Choose destination directory..."' VAR destdir
  33. else
  34.     destdir = ':NONE:'
  35.  
  36. REQUEST_LIST TITLE '"Choose output format..."' STRINGS,
  37.     '"IFF-ILBM"',
  38.     '"IFF-DEEP"',
  39.     '"BMP"',
  40.     '"EPS"',
  41.     '"GIF"',
  42.     '"JPEG"',
  43.     '"PCX"',
  44.     '"PNG"',
  45.     '"PNM"',
  46.     '"QRT"',
  47.     '"SGI"',
  48.     '"TIFF"',
  49.     '"VMEM"',
  50.     '"Targa"' STEM saveformat.
  51.  
  52. /* Set up a blank ARGS string, which we can add to */
  53.  
  54. saveargs = 'ARGS "'
  55.  
  56. /* Get any IFF-ILBM args ? */
  57.  
  58. if saveformat.string == 'IFF-ILBM' then do
  59.     /* Get a subformat */
  60.  
  61.     REQUEST_MESSAGE TEXT '"Choose ILBM format..."' BUTTONTEXT,
  62.         '"As buffer|HAM6|HAM8|EHB|Cancel"' AUTOCANCEL
  63.  
  64.     /* Store subformat */
  65.  
  66.     if result == 2 then
  67.         saveargs = saveargs||'SUBFORMAT HAM6'
  68.     else if result == 3 then
  69.         saveargs = saveargs||'SUBFORMAT HAM8'
  70.     else if result == 4 then
  71.         saveargs = saveargs||'SUBFORMAT EHB'
  72.  
  73.     /* Get the dither if not saving as buffer */
  74.  
  75.     if result ~= 1 then do
  76.         REQUEST_MESSAGE TEXT '"Choose ILBM dither..."' BUTTONTEXT,
  77.             '"None|Floyd-Steinberg|Cancel"' AUTOCANCEL
  78.  
  79.         /* Store the dither */
  80.  
  81.         if result == 2 then
  82.             saveargs = saveargs||' DITHER FS'
  83.  
  84.     end
  85.  
  86.     /* Ask whether should set screenmode of images */
  87.  
  88.     REQUEST_MESSAGE TEXT '"Set screenmode of images?"',
  89.         BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  90.  
  91.     if result == 1 then do
  92.         setscreenmode = 1
  93.  
  94.         REQUEST_SCREENMODE STEM screenmode.
  95.  
  96.         imagescreenmode = screenmode.modeid
  97.  
  98.         end
  99.     else
  100.         setscreenmode = 0
  101. end
  102.  
  103. else if saveformat.string == 'GIF' then do
  104.  
  105.     REQUEST_MESSAGE TEXT '"Interlace?"' BUTTONTEXT,
  106.         '"YES|NO|Cancel"' AUTOCANCEL
  107.  
  108.     if result == 1 then
  109.         saveargs = saveargs||' INTERLACE'
  110.  
  111.     REQUEST_MESSAGE TEXT '"Choose Subformat"' BUTTONTEXT,
  112.         '"GIF87a|GIF89a|Cancel"' AUTOCANCEL
  113.     
  114.     if result == 1 then
  115.         saveargs = saveargs||' SUBFORMAT=GIF87a'
  116.     else do
  117.         saveargs = saveargs||' SUBFORMAT=GIF89a'
  118.  
  119.         REQUEST_MESSAGE TEXT '"Transparency?"' BUTTONTEXT,
  120.             '"Yes|No|Cancel"' AUTOCANCEL
  121.  
  122.         if result == 1 then do
  123.             
  124.             REQUEST_STRING TEXT1 '"Enter the tranparency colour"',
  125.                 TEXT2 '"(Valid values palette range):"',
  126.                 STRING 0 VAR colourinfo
  127.  
  128.             saveargs = saveargs||' TRANSPARENCY TRANSPCOLOUR '||colourinfo
  129.         end
  130.  
  131.     end
  132.     
  133. end
  134.  
  135. else if saveformat.string == 'EPS' then do
  136.     /* Get the DPI of the image */
  137.  
  138.     REQUEST_STRING TEXT1 '"Enter the DPI resolution of"',
  139.         TEXT2 '"the EPS files to be saved:"',
  140.         STRING 300 VAR dpiinfo
  141.  
  142.     saveargs = saveargs||dpiinfo
  143.  
  144.     /* Ask whether to save as colour or greyscale */
  145.  
  146.     REQUEST_MESSAGE TEXT '"Greyscale or colour EPS?"' BUTTONTEXT,
  147.         '"Greyscale|Colour|Cancel"' AUTOCANCEL
  148.  
  149.     if result == 2 then
  150.         saveargs = saveargs||' COLOUR'
  151. end
  152.  
  153. else if saveformat.string == 'JPEG' then do
  154.     /* Get the DPI of the image */
  155.  
  156.     REQUEST_STRING TEXT1 '"Enter the JPEG quality setting"',
  157.         TEXT2 '"for the files to be saved."',
  158.         TEXT3 '"(Valid values 25 to 100):"',
  159.         STRING 75 VAR qualityinfo
  160.  
  161.     saveargs = saveargs||qualityinfo
  162.  
  163.     /* Ask whether to save as colour or greyscale */
  164.  
  165.     REQUEST_MESSAGE TEXT '"Greyscale or colour JPEG?"' BUTTONTEXT,
  166.         '"Greyscale|Colour|Cancel"' AUTOCANCEL
  167.  
  168.     if result == 1 then
  169.         saveargs = saveargs||' GREYSCALE'
  170.  
  171. end
  172.  
  173. else if saveformat.string == 'PNG' then do
  174.  
  175.     REQUEST_MESSAGE TEXT '"Interlace?"' BUTTONTEXT,
  176.         '"YES|NO|Cancel"' AUTOCANCEL
  177.  
  178.     if result == 1 then
  179.         saveargs = saveargs||' INTERLACE=ADAM7'
  180.  
  181.  
  182.     REQUEST_MESSAGE TEXT '"Transparency?"' BUTTONTEXT,
  183.         '"Yes|No|Cancel"' AUTOCANCEL
  184.  
  185.     if result == 1 then do
  186.         
  187.         REQUEST_STRING TEXT1 '"Enter the tranparency colour"',
  188.             TEXT2 '"(Valid values palette range):"',
  189.             STRING 0 VAR colourinfo
  190.  
  191.         saveargs = saveargs||' TRANSPARENCY TRANSPCOLOUR '||colourinfo
  192.  
  193.     end
  194. end    
  195.  
  196. else if saveformat.string == 'PNM' then do
  197.     REQUEST_LIST TITLE '"Choose subformat"' STRINGS,
  198.         '"PBM"',
  199.         '"PGM"',
  200.         '"PPM"' STEM PNMsubf.
  201.         
  202.     saveargs = saveargs||' '||PNMsubf.string
  203.     
  204.     REQUEST_MESSAGE TEXT '"ACSII file?"' BUTTONTEXT,
  205.         '"Yes|No|Cancel"' AUTOCANCEL
  206.         
  207.     if result == 1 then 
  208.         saveargs = saveargs||' ASCII'
  209. end
  210.  
  211. else if saveformat.string == 'SGI' then do
  212.     REQUEST_MESSAGE TEXT '"Greyscale?"' BUTTONTEXT,
  213.         '"Yes|No|Cancel"' AUTOCANCEL
  214.         
  215.     if result == 1 then 
  216.         saveargs = saveargs||' GREYSCALE'
  217.  
  218.     REQUEST_MESSAGE TEXT '"Compressed?"' BUTTONTEXT,
  219.         '"Yes|No|Cancel"' AUTOCANCEL
  220.         
  221.     if result == 1 then 
  222.         saveargs = saveargs||' COMPRESSED'
  223. end
  224.  
  225. else if saveformat.string == 'TIFF' then do
  226.     REQUEST_STRING TEXT1 '"Enter desired DPI"',
  227.         STRING 300 VAR dpiinfo
  228.         
  229.     saveargs = saveargs||' COMPRESSION=NONE DPI='||dpiinfo
  230. end
  231.  
  232.  
  233. /* We may or may not have created an ARGS string. If we have, lets */
  234. /* finish it off, else lets delete it */
  235.  
  236. if saveargs == 'ARGS "' then
  237.     saveargs = ''
  238. else
  239.     saveargs = saveargs||'"'
  240.  
  241. /* Rename filenames ? */
  242.  
  243. REQUEST_MESSAGE TEXT '"Rename filenames ?"' BUTTONTEXT,
  244.     '"Yes|No|Cancel"' AUTOCANCEL
  245.  
  246. if result == 1 then do
  247.     /* Set the rename files */
  248.  
  249.     renamefiles = 1
  250.  
  251.     /* Get the rename pattern */
  252.  
  253.     REQUEST_STRING TEXT1 '"Choose the filename extension"',
  254.         TEXT2 '"for example: .pcx .ilbm"',
  255.         TEXT3 '"would rename all PCX files to ILBM"',
  256.         STRING '". .'||saveformat.string||'"',
  257.         VAR renamestring
  258.     end
  259. else
  260.     renamefiles = 0
  261.  
  262. /* If we're renaming, we should ask if they want the source file */
  263. /* deleted. If we're not renaming, we should warn the user that */
  264. /* the source file will be overwritten. */
  265.  
  266. if renamefiles == 1 then do
  267.     REQUEST_MESSAGE TEXT '"Delete source files ?"',
  268.         BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  269.  
  270.     if result == 1 then
  271.         deletesource = 1
  272.     else
  273.         deletesource = 0
  274.     end
  275. else if renamefiles == 0 & destdir == ':NONE:' then
  276.     REQUEST_MESSAGE TEXT '"WARNING : Source files will\nbe overwritten."',
  277.         BUTTONTEXT '"OK|Cancel"' AUTOCANCEL
  278.  
  279. /* Ask user for process(s) to apply to image before saving out */
  280.  
  281. REQUEST_STRING TITLE '"Enter processes to apply..."',
  282.     TEXT1 '"Enter the processes to apply before"',
  283.     TEXT2 '"saving out the image (separate "',
  284.     TEXT3 '"commands with semi-colon ;)"' VAR process
  285.  
  286. /* Loop around and convert all the files */
  287.  
  288. do l = 0 to (srcfiles.files.count - 1)
  289.     /* Open the file */
  290.  
  291.     OPEN FILE '"'srcfiles.files.l'"' FORCE
  292.  
  293.     /* If you wish to customize this macro to perform any operations */
  294.     /* on the image before saving it out (e.g. resizing, colour */
  295.     /* reduction etc...), add the commands here */
  296.  
  297.     interpret process
  298.  
  299.     /* Set the screenmode if neccessary */
  300.  
  301.     if setscreenmode == 1 then
  302.         IMAGEINFO_SET MODEID imagescreenmode
  303.  
  304.     /* Create the output filename */
  305.  
  306.     if destdir ~= ':NONE:' then do
  307.         /* Get the filepart of the source filename */
  308.  
  309.         FILE_SPLIT FILE '"'srcfiles.files.l'"' STEM filesplit.
  310.  
  311.         /* Create the destfile */
  312.  
  313.         FILE_JOIN PATHPART '"'destdir'"',
  314.             FILEPART '"'filesplit.filepart'"' VAR 'destfile'
  315.  
  316.         end
  317.     else
  318.         destfile = srcfiles.files.l
  319.  
  320.     /* Rename file ? */
  321.  
  322.     if renamefiles == 1 then 
  323.         FILE_RENAME FILE '"'destfile'"' renamestring,
  324.             VAR 'destfile'
  325.  
  326.     /* Save the fileout in the new format */
  327.  
  328.     SAVE FILE '"'destfile'"' FORMAT '"'saveformat.string'"',
  329.         saveargs FORCE
  330.  
  331.     /* Delete source file (and icon) if required */
  332.  
  333.     if renamefiles == 1 & deletesource == 1 then do
  334.         /* Make sure hasn't been renamed to same name */
  335.  
  336.         if upper(srcfiles.files.l) == upper(destfile) then
  337.             break
  338.  
  339.         address command 'delete <NIL: >NIL: "'||srcfiles.files.l||'"'
  340.  
  341.         if exists(srcfiles.files.l||'.info') == 1 then
  342.             address command 'delete <NIL: >NIL: "'||,
  343.                 srcfiles.files.l||'.info"'
  344.         end
  345.     end
  346.  
  347.  
  348. /* END PROGRAM ***************************************************/
  349.  
  350. exit
  351.  
  352. /* On ERROR */
  353.  
  354. ERROR:
  355.  
  356. /* If we get here, either an error occurred with the command's */
  357. /* execution or there was an error with the command itself. */
  358. /* In the former case, rc2 contains the error message and in */
  359. /* the latter, rc2 contains an error number. SIGL contains */
  360. /* the line number of the command which caused the jump */
  361. /* to ERROR: */
  362.  
  363. if datatype(rc2,'NUMERIC') == 1 then do
  364.     /* See if we can describe the error with a string */
  365.  
  366.     select
  367.         when rc2 == 103 then
  368.             err_string = "ERROR 103, "||,
  369.                 "out of memory at line "||SIGL
  370.         when rc2 == 114 then
  371.             err_string = "ERROR 114, "||,
  372.                 "bad command template at line "||SIGL
  373.         when rc2 == 115 then
  374.             err_string = "ERROR 115, "||,
  375.                 "bad number for /N argument at line "||SIGL
  376.         when rc2 == 116 then
  377.             err_string = "ERROR 116, "||,
  378.                 "required argument missing at line "||SIGL
  379.         when rc2 == 117 then
  380.             err_string = "ERROR 117, "||,
  381.                 "value after keywork missing at line "||SIGL
  382.         when rc2 == 118 then
  383.             err_string = "ERROR 118, "||,
  384.                 "wrong number of arguments at line "||SIGL
  385.         when rc2 == 119 then
  386.             err_string = "ERROR 119, "||,
  387.                 "unmatched quotes at line "||SIGL
  388.         when rc2 == 120 then
  389.             err_string = "ERROR 120, "||,
  390.                 "line too long at line "||SIGL
  391.         when rc2 == 236 then
  392.             err_string = "ERROR 236, "||,
  393.                 "unknown command at line "||SIGL
  394.         otherwise
  395.             err_string = "ERROR "||rc2||", at line "||SIGL
  396.         end
  397.         end
  398. else if rc2 == 'RC2' then do
  399.     err_string = "ERROR in command at line "||SIGL
  400.     end
  401. else do
  402.         err_string = rc2||", line "||SIGL
  403.         end
  404.  
  405. request_message TEXT '"'err_string'"'
  406.  
  407. exit
  408.